<template>
	<view class="beijingse">
		<view class="margin_top1 ffffff mainpadding">
			<view class="xiahuaxian flexleft">
				<view class="xiaohei ershiba" style="min-width: 200rpx;">真实姓名</view>
				<input placeholder="请输入姓名" type="text" v-model="ali_name" />
			</view>
			<view class="xiahuaxian flexleft margin_top">
				<view class="xiaohei ershiba" style="min-width: 200rpx;">支付宝账号</view>
				<input placeholder="请输入支付宝账号" type="number" v-model="ali_account" />
			</view>
			<view class="xiahuaxian flexleft margin_top">
				<view class="xiaohei ershiba" style="min-width: 200rpx;">手机号码</view>
				<input placeholder="请输入手机号码" type="text" disabled="" v-model="mobile" />
			</view>
			<view class="xiahuaxian margin_top">
				<uni-captcha scene="zfbcer" v-model="imgcode"></uni-captcha>
			</view>
			<view class=" flexleft margin_top">
				<view class="xiaohei ershiba" style="min-width: 200rpx;">验证码</view>
				<view class="flexbetween">
					<input placeholder="请输入验证码" type="number" v-model="yzm_code" />
					<view class="xiaocheng xiaohuang textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 1">获取验证码</view>
					<view class="xiaocheng xiaohuang textcenter" style="width: 240rpx;" v-show="codetext == 2">
						{{second}}s后重新获取</view>
					<view class="xiaocheng xiaohuang textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 3">重新发送</view>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submitFn()">立即绑定</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				ali_account: "",
				ali_name: "",
				captcha: "",
				codetext: 1,
				second: 59,
				mobile: '',
				yzm_code: '',
				imgcode: ""
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			//发送验证码
			sendyzm() {
				let _this = this;
				if (_this.mobile == '') {
					httpRequest.toast("请输入手机号码!")
					return;
				}
				if (!_this.isMobile(_this.mobile)) {
					httpRequest.toast("手机号码格式错误!")
					return;
				}
				if (this.imgcode=="") {
					httpRequest.toast("请输入图形验证码!")
					return;
				}
				let device = uni.getSystemInfoSync();
				httpRequest.request('/api/sms/send', 'POST', {
					mobile: this.mobile,
					event: 'zfbcer',
					code: this.imgcode,
					deviceId: device.deviceId,
					scene: 'zfbcer',
				}, false, true, false).then(res => {
					if (res.code == 1) {
						_this.codetext = 2;
						_this.second = 59;
						let timer = setInterval(function() {
							if (_this.second > 1) {
								_this.second--;
							} else {
								clearInterval(timer);
								_this.codetext = 3;
							}
						}, 1000)
						httpRequest.toast('发送成功')
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.mobile = res.data.mobile
					this.ali_account = res.data.ali_account
					this.ali_name = res.data.ali_name

				})
			},
			submitFn() {
				if (this.ali_account == "") {
					httpRequest.toast("请输入支付宝账号")
					return false
				}
				if (this.ali_name == "") {
					httpRequest.toast("请输入真实姓名")
					return false
				}
				if (this.yzm_code == "") {
					httpRequest.toast("请输入验证码")
					return false
				}
				httpRequest.request('/api/user/editAliInfo', 'GET', {
					ali_account: this.ali_account,
					ali_name: this.ali_name,
					captcha: this.yzm_code,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}

				})
			},
		}
	}
</script>

<style>

</style>